package patrol.mobile.com.mobilepatrol.activity.bridge.offen;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.bean.Qljcxjcb;
import patrol.mobile.com.mobilepatrol.listener.TimeListener;
import patrol.mobile.com.mobilepatrol.manager.QManager;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;

import static patrol.mobile.com.mobilepatrol.R.id.et;
import static patrol.mobile.com.mobilepatrol.R.id.tv;

/**
 * Created by apple on 17/9/27.
 */

public class OffenCheckDetailActivity extends BaseActivity {
//    @BindView(R.id.itme1)
//    RelativeLayout rl1;

    @BindView(R.id.itme2)
    RelativeLayout rl2;

    @BindView(R.id.itme3)
    RelativeLayout rl3;
    @BindView(R.id.itme4)
    RelativeLayout rl4;
    @BindView(R.id.itme5)
    RelativeLayout rl5;
    @BindView(R.id.itme6)
    RelativeLayout rl6;
    @BindView(R.id.itme7)
    RelativeLayout rl7;
    @BindView(R.id.itme8)
    RelativeLayout rl8;
    @BindView(R.id.itme9)
    RelativeLayout rl9;
    @BindView(R.id.itme10)
    RelativeLayout rl10;


    @BindView(R.id.bt_save)
    Button bt_save;

    @BindView(R.id.bt_list)
    Button bt_list;

//    private EditText et1;
    private EditText et2;
    private EditText et3;
    private EditText et4;
    private EditText et5;
    private EditText et6;
    private EditText et7;
    private EditText et8;
    private EditText et9;
    private TextView tv11;

    private Qljcxjcb qljcxjcb;
    private String qljcxjcid;
    private String qlcode;


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_offen_check_detail;
    }

    @Override
    public void setListener() {
        bt_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                String qljcxjcid = et1.getText().toString().trim();
                String roadcode = et2.getText().toString().trim();
                String roadname = et3.getText().toString().trim();
                String roadpos = et4.getText().toString().trim();
                String qlcode = et5.getText().toString().trim();
                String qlname = et6.getText().toString().trim();
                String gydw = et7.getText().toString().trim();

                String jlr = et8.getText().toString().trim();
                String fzr = et9.getText().toString().trim();
                String time = tv11.getText().toString().trim();
                Qljcxjcb b = new Qljcxjcb();
                b.roadcode = roadcode;
                b.roadname = roadname;
                b.roadpos = roadpos;
                b.qlcode = qlcode;
                b.qlname = qlname;
                b.gydw = gydw;
                b.jlr = jlr;
                b.fzr = fzr;
                b.jcrq = time;
                b.id = qljcxjcid;
                QManager.alterBridgeJC(b);
                QManager.setBridegJCUpState(qljcxjcid,false);
                QManager.setQLUpState(b.qlcode,false);
                showToast("保存成功");
            }
        });
        bt_list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //检查桥梁id，经常检查id
                Intent intent = new Intent(OffenCheckDetailActivity.this,BridgeOffenCheckBrokenListActivity.class);
                intent.putExtra("qljcxjcid",qljcxjcid);
                intent.putExtra("qlcode",qlcode);
                startActivity(intent);
                CommonUtil.openNewActivityAnim(OffenCheckDetailActivity.this,false);
            }
        });
        tv11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.showDatePickDlg(OffenCheckDetailActivity.this, new TimeListener() {
                    @Override
                    public void getDate(String date) {
                        tv11.setText(date);
                    }
                });
            }
        });

    }

    @Override
    public void initView() {
        super.initView();
//        TextView tv1 = rl1.findViewById(tv);
//        tv1.setText("桥梁经常性检查id");
//        et1 = rl1.findViewById(et);

        TextView tv2 = rl2.findViewById(tv);
        tv2.setText("路线编码");
        et2 = rl2.findViewById(et);

        TextView tv3 = rl3.findViewById(tv);
        tv3.setText("路线名称");
        et3 = rl3.findViewById(et);

        TextView tv4 = rl4.findViewById(tv);
        tv4.setText("桥位桩号");
        et4 = rl4.findViewById(et);

        TextView tv5 = rl5.findViewById(tv);
        tv5.setText("桥梁编码");
        et5 = rl5.findViewById(et);

        TextView tv6 = rl6.findViewById(tv);
        tv6.setText("桥梁名称");
        et6 = rl6.findViewById(et);

        TextView tv7 = rl7.findViewById(tv);
        tv7.setText("管养单位");
        et7 = rl7.findViewById(et);

        TextView tv8 = rl8.findViewById(tv);
        tv8.setText("记录人");
        et8 = rl8.findViewById(et);

        TextView tv9 = rl9.findViewById(tv);
        tv9.setText("负责人");
        et9 = rl9.findViewById(et);

        TextView tv10 = rl10.findViewById(tv);
        tv10.setText("检查日期");
        tv11 = rl10.findViewById(R.id.tv1);
        tv11.setText(CommonUtil.getCurrentDate());



    }

    @Override
    public void initData() {
        super.initData();
        qljcxjcid = getIntent().getStringExtra("qljcxjcid");
         qlcode = getIntent().getStringExtra("qlcode");
        qljcxjcb = QManager.getBridgeJC(qlcode,qljcxjcid);

        setData();

    }

    private void setData() {
//        et1.setText(qljcxjcb.id);

        et2.setText(qljcxjcb.roadcode);

        et3.setText(qljcxjcb.roadname);

        et4.setText(qljcxjcb.roadpos+"");

        et5.setText(qljcxjcb.qlcode);

        et6.setText(qljcxjcb.qlname);

        et7.setText(qljcxjcb.gydw+"");

        et8.setText(qljcxjcb.jlr);

        et9.setText(qljcxjcb.fzr+"");

        tv11.setText(qljcxjcb.jcrq);
    }

    @Override
    public void initTitle() {
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(OffenCheckDetailActivity.this,true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText("经常检查");
    }
}
